const http = require("http");
const url = require("url");

const server = http.createServer((req, res) => {
  const { pathname } = url.parse(req.url);
  console.log(req.method);

  if (pathname === "/login") {
    if (req.method === "POST") {
      req.setEncoding("utf-8");
      req.on("data", (data) => {
        console.log(JSON.parse(data));
      });
    }
  }
  res.end("欢迎回来");
});

server.listen(8000, "0.0.0.0", () => {
  console.log("服务器启动成功");
});
